<?php


namespace app\server\controller;

use app\server\model\Coupon as CouponModel;
use app\index\controller\Base;
class Coupon extends Base
{
    /***
     * 获取优惠卷信息
     */
    public function get()
    {
        $data = $this->request->param();
        $res = new CouponModel();
        $d = $res->with("couponServers.servers")
        ->where($data['field'],$data['op'],$data['value'])
        ->order('cTime desc')
        ->page($data['page'])
        ->limit(10)
        ->select();
        return $d;
    }
    public function getlist()
    {
        $data = $this->request->param();
        $res = new CouponModel();
        $d = $res->with("couponServers.servers")
        ->where('id','>','0')
        ->where('is_delete=0')
        ->where('price','>','0')
        ->order('cTime desc')
        ->page($data['page'])
        ->limit(10)
        ->select();
        return $d;
    }
    /**
     * 保存优惠卷
     */
    public function save()
    {
        $res = new CouponModel();
        $data = $this->request->param();
        $d=$res->saveModel($data);
        return $d->id;
    }
    public function delete()
    {
        $res = new CouponModel();
        $data = $this->request->param();
        $res->deleteModel($data);
    }
    public function update()
    {
        $res = new CouponModel();
        $data = $this->request->param();
        $res->updateModel($data);
    }
    public function num(){
        $data = $this->request->param();
        $res =new CouponModel();
        return $res->where($data['field'],$data['op'],$data['value'])->count();
    }
}